package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.RepairOrders;
import com.ruoyi.system.mapper.RepairOrdersMapper;
import com.ruoyi.system.service.IRepairOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 设备维修工单记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@Service
public class RepairOrdersServiceImpl implements IRepairOrdersService {
    @Autowired
    private RepairOrdersMapper repairOrdersMapper;

    /**
     * 查询设备维修工单记录
     *
     * @param repairOrderCode 设备维修工单记录主键
     * @return 设备维修工单记录
     */
    @Override
    public RepairOrders selectRepairOrdersByRepairOrderCode(String repairOrderCode) {
        return repairOrdersMapper.selectRepairOrdersByRepairOrderCode(repairOrderCode);
    }

    /**
     * 查询设备维修工单记录列表
     *
     * @param repairOrders 设备维修工单记录
     * @return 设备维修工单记录
     */
    @Override
    public List<RepairOrders> selectRepairOrdersList(RepairOrders repairOrders) {
        return repairOrdersMapper.selectRepairOrdersList(repairOrders);
    }

    /**
     * 新增设备维修工单记录
     *
     * @param repairOrders 设备维修工单记录
     * @return 结果
     */
    @Override
    public int insertRepairOrders(RepairOrders repairOrders) {
        repairOrders.setCreateTime(DateUtils.getNowDate());
        repairOrders.setRepairOrderCode(IdUtils.fastSimpleUUID());
        repairOrders.setRepairTime(new Date());
        repairOrders.setMaintainerId(SecurityUtils.getUserId().toString());
        repairOrders.setMaintainerName(SecurityUtils.getUserId().toString());
        repairOrders.setRepairTime(new Date());
        return repairOrdersMapper.insertRepairOrders(repairOrders);
    }

    /**
     * 修改设备维修工单记录
     *
     * @param repairOrders 设备维修工单记录
     * @return 结果
     */
    @Override
    public int updateRepairOrders(RepairOrders repairOrders) {
        repairOrders.setUpdateTime(DateUtils.getNowDate());
        return repairOrdersMapper.updateRepairOrders(repairOrders);
    }

    /**
     * 批量删除设备维修工单记录
     *
     * @param repairOrderCodes 需要删除的设备维修工单记录主键
     * @return 结果
     */
    @Override
    public int deleteRepairOrdersByRepairOrderCodes(String[] repairOrderCodes) {
        return repairOrdersMapper.deleteRepairOrdersByRepairOrderCodes(repairOrderCodes);
    }

    /**
     * 删除设备维修工单记录信息
     *
     * @param repairOrderCode 设备维修工单记录主键
     * @return 结果
     */
    @Override
    public int deleteRepairOrdersByRepairOrderCode(String repairOrderCode) {
        return repairOrdersMapper.deleteRepairOrdersByRepairOrderCode(repairOrderCode);
    }
}
